$(function(){
	var walletType=sessionStorage.getItem("walletType");
	var logonToken=sessionStorage.getItem("logonToken");
	var playId=sessionStorage.getItem("playId");
	
//	获取数据
 	var json = {
        "logonToken": logonToken,
        "walletType": walletType,
        "playId":playId
    }
	$.ajax({
		type:"post",
		url:url + '/bigWinner/api/rechargeRecord/rechargeRecordPage',
		data:JSON.stringify(json),
		dataType:'json',
		contentType: "application/json;charset=UTF-8",
		success:function(result){
			if(result.success){
				$("#foo").val(result.obj.totalWalletAddress);
//                                makeCode();
			}else{
				isErr(result);
			}
		},
		error:function (XMLHttpRequest, textStatus, errorThrown) { 
			alert("请求失败："+XMLHttpRequest.status);
		}
	});
	
//	充币提交
	$(".Charge_btn").on("click",function(){
		var txhash=$('.money_num_input').val();
		if(!txhash){
			alert("请输入TxHash！");
			return false;
		}
		$("#exampleModal").modal("toggle");
	})
	
	var prevent_repetition = true;
	$(".money_btn").on("click",function(){
		if (prevent_repetition) {
            prevent_repetition = false;
            var payPassword = $("#recipient-name1").val();
            var totalWalletaddress=$("#foo").val();
            var txhash=$('.money_num_input').val();
            if (!payPassword) {
                alert("请输入支付密码");
                prevent_repetition = true;
                return false;
            }
            var json = {
                "logonToken": logonToken,
		        "walletType": walletType,
		        "playId":playId,
		        "totalWalletaddress": totalWalletaddress,
		        "payPassword": payPassword,
		        "txhash":txhash
            }
            $.ajax({
                type: "post",
                url: url + '/bigWinner/api/rechargeRecord/recharge',
                data: JSON.stringify(json),
                dataType: 'json',
                contentType: "application/json",
                success: function(result) {
                    if (result.success) {
                        alert(result.msg);
                        $("#exampleModal").modal("toggle");
//                      初始化充币记录
                        $(".load_more").html("加载更多....");
                        $(".modal_list").html("");
                        page = 1;
                        chargMoney_list(page);
                        window.location.reload();
                    } else {
                        isErr(result);
                    }
                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                   alert("请求失败："+XMLHttpRequest.status);
                },
                complete: function() {
                    prevent_repetition = true;
                }
            });
        }
	})
	
	var page=1;
	var rows=10;
	
//	充币记录
	function chargMoney_list(page){
		var json1 = {
	        "logonToken": logonToken,
	        "walletType": walletType,
	        "playId":playId,
	        "page":page,
	        "rows":rows
	  	}
		$.ajax({
			type:"post",
			url:url + '/bigWinner/api/rechargeRecord/rechargeRecord',
			data:JSON.stringify(json1),
			dataType:'json',
			contentType: "application/json;charset=UTF-8",
			success:function(result){
				if(result.success){
					var html='';
					var data=result.obj.rechargeRecordList;
					for(var i in data){
						html += '<div class="modal_charge_record">';
	                    html += '<p>ID<span>'+data[i].id+'</span></p>';
	                    if(data[i].type == "1"){
	                    	html += '<p>币种<span>ETH</span></p>';
	                    }else{
	                    	html += '<p>币种<span>BTC</span></p>';
	                    }
	                    html += '<p>充币地址<span>'+data[i].toAddress+'</span></p>';
	                    html += '<p>交易单号<span>'+data[i].txhash+'</span></p>';
	                    if(data[i].amount == null){
	                    	html += '<p>充币数量<span></span></p>';
	                    }else{
	                    	html += '<p>充币数量<span>'+data[i].amount+'</span></p>';
	                    }
	                    
	                    html += '<p>申请时间<span>'+data[i].addTime+'</span></p>';
	                    
	                    if(data[i].checkStatus == "0"){
	                    	html += '<p>审核时间<span></span></p>';
	                    	html += '<p>审核状态<span>未审核</span></p></div>';
	                    }else if(data[i].checkStatus == "1"){
	                    	html += '<p>审核时间<span>'+data[i].checkTime+'</span></p>';
	                    	html += '<p>审核状态<span>已通过</span></p></div>';
	                    }else if(data[i].checkStatus == "2"){
	                    	html += '<p>审核时间<span>'+data[i].checkTime+'</span></p>';
	                    	html += '<p>审核状态<span>不通过</span></p></div>';
	                    }
					}
					$(".modal_list").append(html);
				}else{
					$(".load_more").html("暂无更多记录");
				}
			},
			error:function (XMLHttpRequest, textStatus, errorThrown) { 
				alert("请求失败："+XMLHttpRequest.status);  
			}
		});
	}
	
	chargMoney_list(page);
	
	$(".load_more").on("click",function(){
		page++;
		chargMoney_list(page,1);
	});
        //	生成二维码
//        var qrcode = new QRCode(document.getElementById("QR"), {
//            width: 100,
//            height: 100
//        });
//
//        function makeCode() {
//            var elText = document.getElementById("foo");
//            if (!elText.value) {
//                alert("Input a text");
//                elText.focus();
//                return;
//            }
//            qrcode.makeCode(elText.value);
//        }
})
